package db

/*
gentool -dsn "root:OTc7ohMdsN,W@tcp(localhost:3306)/database?charset=utf8mb4&parseTime=True&loc=Local" -tables "orders,doctor"

sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm
Data
Uploads
 k&7Aqj/4HuKu
mysqld --install   mysql3308

mysqld --initialize --console

hwa4I?:9WT65
mysql -h 127.0.0.1 -uroot -p -P3308
ALTER USER USER() IDENTIFIED BY 'Gr!123456#A';

shell.connect('root@localhost:3306');
dba.checkInstanceConfiguration('root@127.0.0.1:3306')
dba.configureInstance()
GRANT CLONE_ADMIN, CONNECTION_ADMIN, GROUP_REPLICATION_ADMIN, PERSIST_RO_VARIABLES_ADMIN, REPLICATION_APPLIER, REPLICATION_SLAVE_ADMIN, ROLE_ADMIN, SYSTEM_VARIABLES_ADMIN ON *.* TO 'root'@'%' WITH GRANT OPTION;

shell.connect('root@localhost:3307');
dba.checkInstanceConfiguration('root@127.0.0.1:3307')
dba.configureInstance()

shell.connect('root@localhost:3308');
dba.checkInstanceConfiguration('root@127.0.0.1:3308')
dba.configureInstance()
Gr!123456#A

shell.connect('root@localhost:3306');
 var cluster = dba.createCluster('testCluster');  # 创建一个 cluster，命名为 'testCluster'
cluster.addInstance('root@127.0.0.1:3307');
cluster.status();

gentool -db "sqlserver" -dsn "sqlserver://sa:YRQ@iotzhxf_2020$SC@127.0.0.1:1433?database=DBMaster&encrypt=disable" -tables "tbid"

gentool -db "sqlserver" -dsn "goroot:Gr!123456#A$SC@127.0.0.1:1433?database=DBMaster&encrypt=disable" -tables "tbid"


gentool -db "mysql" -dsn "root:Gr!123456#A@tcp(127.0.0.1:4306)/iotdb?charset=utf8&parseTime=True&loc=Local&timeout=1000ms" -tables "tbid"



mysql-js> shell.connect('root@db-node01:3000');         # 连接db-node01，主节点，创建集群后是读写权限，其他节点只读
Please provide the password for 'root@db-node01:3000':         # 输入密码
Creating a Session to 'root@db-node01:3000'
Classic Session successfully established. No default schema selected.

mysql-js> var cluster = dba.createCluster('testCluster');  # 创建一个 cluster，命名为 'testCluster'
A new InnoDB cluster will be created on instance 'root@db-node01:3000'.

Creating InnoDB cluster 'testCluster' on 'root@db-node01:3000'...
Adding Seed Instance...

Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.
At least 3 instances are needed for the cluster to be able to withstand up to
one coreserver failure.

如上的信息, 如果创建成功, 则会输出的信息中会有类似“Cluster successfully created.”的语句

#创建成功后，查看cluster状态
mysql-js> cluster.status();
{
    "clusterName": "testCluster",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "db-node01:3000",
        "status": "OK_NO_TOLERANCE",
        "statusText": "Cluster is NOT tolerant to any failures.",
        "topology": {
            "db-node01:3000": {
                "address": "db-node01:3000",
                "mode": "R/W",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            }
        }
    }
}
mysql-js> cluster.addInstance('root@db-node02:3000');
A new instance will be added to the InnoDB cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.

Please provide the password for 'root@db-node02:3000':
Adding instance to the cluster ...

The instance 'root@db-node02:3000' was successfully added to the cluster.

mysql-js> cluster.addInstance('root@db-node03:3000');
A new instance will be added to the InnoDB cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.

Please provide the password for 'root@db-node03:3000':
Adding instance to the cluster ...

The instance 'root@db-node03:3000' was successfully added to the cluster.

mysql-js> cluster.status();
{
    "clusterName": "testCluster",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "db-node01:3000",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
        "topology": {
            "db-node01:3000": {
                "address": "db-node01:3000",
                "mode": "R/W",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "db-node02:3000": {
                "address": "db-node02:3000",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "db-node03:3000": {
                "address": "db-node03:3000",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            }
        }
    }
}

*/
